import { createSlice } from '@reduxjs/toolkit'

export const playerSlice = createSlice({
    name: 'player',
    initialState: {
        current: {},//当前播放的音乐基本信息
        playingCurrentTime: 0, //正在播放歌曲的进度时间
        playingDuration: 0, //正在播放歌曲的总时间
        playList: [],//当前的播放列表（支持本地存储）
    },
    reducers: {
        //设置当前要播放的歌曲信息
        setCurrentPlay (state, action) {
            state.current = action.payload;
        },
        //设置当前播放歌曲的总时长
        setPlayingDuration (state, action) {
            state.playingDuration = action.payload;
        },
        //设置当前播放歌曲的currentTime
        setPlayingCurrentTime (state, action) {
            state.playingCurrentTime = action.payload;
        }
    },
})

// Action creators are generated for each case reducer function
export const {
    setCurrentPlay, setPlayingDuration, setPlayingCurrentTime
} = playerSlice.actions

export default playerSlice.reducer